import { GCellRenderer } from "../../../../com/mui/controls/GCellRenderer";
import { ClickToShowItemTip } from "../common/tooltip/ClickToShowItemTip";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { SHitEggReward } from "../../../../Message/Game/SHitEggReward";
import { Language } from "../../../../extend/language/Language";
import { EHitEggReReward } from "../../../../Message/Game/EHitEggReReward";
import { ItemConfig } from "../../resource/ItemConfig";
import { Cache } from "../../cache/Cache";
import { ColorConfig } from "../../resource/ColorConfig";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
type int = number;
//class HitEggRewardRenderer
    
    export  class HitEggRewardRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            addEventListener(flash.events.MouseEvent.CLICK, this.onClickHandler);
            addEventListener(flash.events.Event.REMOVED_FROM_STAGE, this.onRemoveFromStage);
            return;
        }

        /* internal  */onClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            arg1.stopImmediatePropagation();
            return;
        }

        /* internal  */onRemoveFromStage(arg1: Object /* flash.events.Event */): void
        {
            if (this._isItemTip) 
            {
                this._isItemTip = false;
                ClickToShowItemTip.instance.hide();
            }
            return;
        }

        protected /* override */ configUI(): void
        {
            super.configUI();
            var loc1=new GTextFormat(FontUtil.xingkaiName, 16, 65280);
            this._nodeTxt = ObjCreate.createGTextField("", 5, 2, 150, 20, this, loc1);
            this._serverContentTxt = ObjCreate.createGTextField("", 5, 21, 150, 20, this);
            this._personContentTxt = ObjCreate.createGTextField("", 5, 36, 150, 20, this);
            this._touchInfoTxt = ObjCreate.createGTextField("", 5, 51, 150, 20, this);
            this._lineBg = ObjCreate.createBg(0, 74, 150, 2, this, ImagesConst.SplitLine);
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc6=null;
            var loc7=null;
            var loc8=null;
            super.data = arg1;
            if (arg1 == null) 
            {
                return;
            }
            this._sHitEggReward = arg1 as SHitEggReward;
            if (this._sHitEggReward) 
            {
                this._nodeTxt.htmlText = Language.getStringByParam(36600, this._sHitEggReward.node);
                loc1 = Language.getString(36601);
                var loc9=this._sHitEggReward.personType;
                switch (loc9) 
                {
                    case EHitEggReReward._EHitEggRewardDropMoney:
                    {
                        loc1 = loc1 + Language.getString(36602);
                        break;
                    }
                    case EHitEggReReward._EHitEggRewardGiveItem:
                    {
                        if (loc5 = ItemConfig.instance.getInfoByCode(this._sHitEggReward.personContent1)) 
                        {
                            loc1 = loc1 + Language.getString(36603) + "<u><a href=\'event:" + loc5.item.code + "\'>" + loc5.htmlName + "</a></u>";
                        }
                        break;
                    }
                    case EHitEggReReward._EHitEggRewardMultExp:
                    {
                        loc1 = loc1 + Language.getStringByParam(36604, this._sHitEggReward.personContent2 / 100 + 1);
                        break;
                    }
                    case EHitEggReReward._EHitEggRewardRefreshBoss:
                    {
                        loc1 = loc1 + this._sHitEggReward.serverContent3;
                        break;
                    }
                }
                this._personContentTxt.htmlText = loc1;
                this._personContentTxt.addEventListener(flash.events.TextEvent.LINK, this.onPersonContentTxtLink);
                loc2 = Language.getString(36606);
                loc9 = this._sHitEggReward.serverType;
                switch (loc9) 
                {
                    case EHitEggReReward._EHitEggRewardDropMoney:
                    {
                        loc2 = loc2 + Language.getString(36602);
                        break;
                    }
                    case EHitEggReReward._EHitEggRewardGiveItem:
                    {
                        if (loc6 = ItemConfig.instance.getInfoByCode(this._sHitEggReward.serverContent1)) 
                        {
                            loc2 = loc2 + Language.getString(36603) + "<u><a href=\'event:" + loc6.item.code + "\'>" + loc6.htmlName + "</a></u>";
                        }
                        break;
                    }
                    case EHitEggReReward._EHitEggRewardMultExp:
                    {
                        loc2 = loc2 + Language.getStringByParam(36604, this._sHitEggReward.serverContent2 / 100 + 1);
                        break;
                    }
                    case EHitEggReReward._EHitEggRewardRefreshBoss:
                    {
                        loc2 = loc2 + this._sHitEggReward.serverContent3;
                        break;
                    }
                }
                this._serverContentTxt.htmlText = loc2;
                this._serverContentTxt.addEventListener(flash.events.TextEvent.LINK, this.onServerContentTxtLink);
                loc3 = Language.getString(36611);
                if (loc4 = Cache.instance.hitEgg.getSHitEggTouchInfoByNode(this._sHitEggReward.node)) 
                {
                    loc7 = "";
                    if (loc8 = ColorConfig.instance.getCampColor(loc4.player.camp)) 
                    {
                        loc7 = loc8.color;
                    }
                    loc3 = loc3 + HTMLUtil.addColor(loc4.player.name, loc7);
                }
                else 
                {
                    loc3 = loc3 + Language.getString(36612);
                }
                this._touchInfoTxt.htmlText = loc3;
            }
            return;
        }

        /* internal  */onPersonContentTxtLink(arg1: Object /* flash.events.TextEvent */): void
        {
            var loc1=int(arg1.text);
            this.setTooltip(loc1);
            return;
        }

        /* internal  */onServerContentTxtLink(arg1: Object /* flash.events.TextEvent */): void
        {
            var loc1=int(arg1.text);
            this.setTooltip(loc1);
            return;
        }

        /* internal  */setTooltip(arg1: int): void
        {
            this._isItemTip = true;
            ClickToShowItemTip.instance.setItemCodeAndShow(arg1);
            return;
        }

        public /* override */ set selected(arg1: Boolean)
        {
            super.selected = arg1;
            this.setSelectBg(arg1);
            return;
        }

        public setSelectBg(arg1: Boolean): void
        {
            if (arg1) 
            {
                if (this._touchBg != null) 
                {
                    this._touchBg.visible = true;
                }
                else 
                {
                    LoaderHelp.addResCallBack(ResFileConst.BreakEgg, this.onResLoaded);
                }
            }
            else if (this._touchBg) 
            {
                this._touchBg.visible = false;
            }
            return;
        }

        /* internal  */onResLoaded(): void
        {
            this._touchBg = GlobalClass.getScaleBitmap(ImagesConst.breakEggInfoBg, new Object /* flash.geom.Rectangle */(50, 30, 54, 1));
            this._touchBg.y = 2;
            this._touchBg.width = 154;
            this._touchBg.height = 70;
            addChildAt(this._touchBg, 0);
            return;
        }

        /* internal */ /* var */_sHitEggReward: SHitEggReward;

        /* internal */ /* var */_nodeTxt: GTextFiled;

        /* internal */ /* var */_personContentTxt: GTextFiled;

        /* internal */ /* var */_serverContentTxt: GTextFiled;

        /* internal */ /* var */_touchInfoTxt: GTextFiled;

        /* internal */ /* var */_lineBg: ScaleBitmap;

        /* internal */ /* var */_touchBg: ScaleBitmap;

        /* internal */ /* var */_isItemTip: Boolean=false;
    }
